package com.pur.zsms.ordercustommanage.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.pur.zsms.common.dao.GenericDao;
import com.pur.zsms.common.dao.JpaTemplate;
import com.pur.zsms.common.exception.GenericException;
import com.pur.zsms.common.support.PageController;
import com.pur.zsms.common.support.PaginationSupport;
import com.pur.zsms.ordercustommanage.dao.CustMaterOrderDao;
import com.pur.zsms.ordercustommanage.po.OrderSupplierPo;
import com.pur.zsms.ordercustommanage.vo.OrderSupplierVo;

@Repository("custMaterOrderDao")
public class CustMaterOrderDaoImpl extends GenericDao implements
        CustMaterOrderDao {

    @Override
    public PaginationSupport listSupplierOrder(PageController pageController,
            OrderSupplierVo orderSupplierVo) throws GenericException {
        return this.findByNativeQuery(
                "select * from t_order_supplier where ord_sup_id ='"
                        + orderSupplierVo.getOrdSupId() + "'",
                OrderSupplierPo.class, pageController);
    }

    @Override
    public OrderSupplierPo getOrderSup(String ordId, String ordCustId,
            String ordSupId) throws GenericException {
        JpaTemplate template = this.getTemplate();
        StringBuffer ql = new StringBuffer();
        ql.append(" select o ");
        ql.append(" from OrderSupplierPo o where o.ordId=" + ordId
                + "and o.ordCustId=" + ordCustId + "and o.ordSupId=" + ordSupId);
        List<OrderSupplierPo> list = template.find(ql.toString(), null);
        return list.get(0);

    }

    @Override
    public void sendmater(OrderSupplierPo orderSupplierPo)
            throws GenericException {
        this.merge(orderSupplierPo);
    }

}
